package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProductionMaterialTracking;
import com.ruoyi.mes.service.IProductionMaterialTrackingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产物料跟踪管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/mes/tracking")
public class ProductionMaterialTrackingController extends BaseController
{
    @Autowired
    private IProductionMaterialTrackingService productionMaterialTrackingService;

    /**
     * 查询生产物料跟踪管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:tracking:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionMaterialTracking productionMaterialTracking)
    {
        startPage();
        List<ProductionMaterialTracking> list = productionMaterialTrackingService.selectProductionMaterialTrackingList(productionMaterialTracking);
        return getDataTable(list);
    }

    /**
     * 导出生产物料跟踪管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:tracking:export')")
    @Log(title = "生产物料跟踪管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionMaterialTracking productionMaterialTracking)
    {
        List<ProductionMaterialTracking> list = productionMaterialTrackingService.selectProductionMaterialTrackingList(productionMaterialTracking);
        ExcelUtil<ProductionMaterialTracking> util = new ExcelUtil<ProductionMaterialTracking>(ProductionMaterialTracking.class);
        util.exportExcel(response, list, "生产物料跟踪管理数据");
    }

    /**
     * 获取生产物料跟踪管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:tracking:query')")
    @GetMapping(value = "/{trackingId}")
    public AjaxResult getInfo(@PathVariable("trackingId") Long trackingId)
    {
        return success(productionMaterialTrackingService.selectProductionMaterialTrackingByTrackingId(trackingId));
    }

    /**
     * 新增生产物料跟踪管理
     */
    @PreAuthorize("@ss.hasPermi('mes:tracking:add')")
    @Log(title = "生产物料跟踪管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionMaterialTracking productionMaterialTracking)
    {
        return toAjax(productionMaterialTrackingService.insertProductionMaterialTracking(productionMaterialTracking));
    }

    /**
     * 修改生产物料跟踪管理
     */
    @PreAuthorize("@ss.hasPermi('mes:tracking:edit')")
    @Log(title = "生产物料跟踪管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionMaterialTracking productionMaterialTracking)
    {
        return toAjax(productionMaterialTrackingService.updateProductionMaterialTracking(productionMaterialTracking));
    }

    /**
     * 删除生产物料跟踪管理
     */
    @PreAuthorize("@ss.hasPermi('mes:tracking:remove')")
    @Log(title = "生产物料跟踪管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trackingIds}")
    public AjaxResult remove(@PathVariable Long[] trackingIds)
    {
        return toAjax(productionMaterialTrackingService.deleteProductionMaterialTrackingByTrackingIds(trackingIds));
    }
}
